package com.fly.service.Impl;

import com.fly.bean.*;
import com.fly.mapper.FixExecuteMapper;
import com.fly.service.FixExecuteService;
import com.fly.util.Page;
import com.fly.vo.FixAllMassage_lmg;
import com.fly.vo.FixPageVO_lmg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FixExecuteServiceImpl implements FixExecuteService {

    @Autowired
    FixExecuteMapper fixExecuteMapper;

    @Override
    public FixPageVO_lmg getAllFixTask(Page page) {
        int count = fixExecuteMapper.getAllFixTaskCount();
        List<Fix> fixes = fixExecuteMapper.getAllFixTask(page);
        page.setCount(count);
        FixPageVO_lmg fixPageVO = new FixPageVO_lmg();
        fixPageVO.setFixes(fixes);
        fixPageVO.setPage(page);
        return fixPageVO;
    }

    @Override
    public FixPageVO_lmg getAllFixTaskUser(Page page, Users user) {
        int count = fixExecuteMapper.getAllFixTaskCountUser(user);
        List<Fix> fixes = fixExecuteMapper.getAllFixTaskUser(user,page);
        page.setCount(count);
        FixPageVO_lmg fixPageVO = new FixPageVO_lmg();
        fixPageVO.setFixes(fixes);
        fixPageVO.setPage(page);
        return fixPageVO;
    }

    @Override
    public Users getUserByUserId(int userId) {
        return fixExecuteMapper.selectUserRoleById(userId);
    }


    @Override
    public List<WorkForm> getAllWorkForm() {
        return fixExecuteMapper.selectAllWorkform();
    }


    /**
     * 通过条件查询
     * @param fixPageVO
     * @return
     */
    @Override
    public FixPageVO_lmg getFixByConditions(FixPageVO_lmg fixPageVO) {
        Page page = fixPageVO.getPage();
        int count = fixExecuteMapper.getFixTaskByConditionsCount(fixPageVO);

        List<Fix> fixes = fixExecuteMapper.getFixTaskByConditions(fixPageVO);
        page.setCount(count);
        fixPageVO.setFixes(fixes);
        return fixPageVO;
    }

    /**
     * 通过条件查询和权限
     * @param fixPageVO
     * @return
     */
    @Override
    public FixPageVO_lmg getFixByConditionsUser(FixPageVO_lmg fixPageVO,Users users) {
        Page page = fixPageVO.getPage();
        int count = fixExecuteMapper.getFixTaskByConditionsCountUser(fixPageVO,users);

        List<Fix> fixes = fixExecuteMapper.getFixTaskByConditionsUser(fixPageVO,users);
        page.setCount(count);
        fixPageVO.setFixes(fixes);
        return fixPageVO;
    }

    @Override
    public List<Task> getFixPoleByTaskId(Task task) {

        return null;
    }

    @Override
    public Fix getFixPoleByFixId(Fix fix) {
        return fixExecuteMapper.getFixById(fix.getFixId());
    }

    @Override
    public List<Users> getUserByTaskId(Integer taskId) {
        return fixExecuteMapper.getUserByTaskId(taskId);
    }

    @Override
    public List<PoleFixRelation> getPoleByFixId(Integer fixId) {
        return fixExecuteMapper.getDemageFixRelationByFixid(fixId);
    }

    @Override
    public Circuitry getCircuitryByPoleId(Integer poleId) {
        return fixExecuteMapper.getCircuitryByPoleId(poleId);
    }

    @Override
    public int updateFixById(Fix fix) {
        return fixExecuteMapper.updateFixById(fix);
    }

    @Override
    public int updateFixTaskStateById(int taskId) {
        return fixExecuteMapper.updateFixTaskStateById(taskId);
    }

    @Override  //获取用户是否有制定任务的消缺任务的权限
    public int getUserCreateFixByUserId(Integer userId) {
        return fixExecuteMapper.getUserCreateFixByUserId(userId);
    }

    @Override
    public List<SystemPropertiesValue> getAllSysProValue(String str) {
        return fixExecuteMapper.getAllSysProValue(str);
    }

    @Override
    public List<Defects> getAllDefects() {
        return fixExecuteMapper.getAllDefects();
    }

    @Override
    public List<Fix> getAllFix() {
        return fixExecuteMapper.getAllFix();
    }

    @Override  //根据任务消缺人员查fix
    public List<Fix> getFixByTask_UserUserid(int userId) {
        return fixExecuteMapper.getFixByTask_UserUserid(userId);
    }

    @Override
    public int getFixPoleCountByFixId(Integer fixId) {
        return fixExecuteMapper.getFixPoleCountByFixId(fixId);
    }

    @Override
    public List<FixAllMassage_lmg> selectFixAllMassage(Page page, FixPageVO_lmg fixPageVO) {
        page.setCount(fixExecuteMapper.selectFixAllMassageCount(fixPageVO));
        return fixExecuteMapper.selectFixAllMassage(page,fixPageVO);
    }

    @Override
    public List<FixAllMassage_lmg> selectFixMassageByCon(Page page, Users user, FixPageVO_lmg fixPageVO) {
        page.setCount(fixExecuteMapper.selectFixMassageCountByCon(user,fixPageVO));
        return fixExecuteMapper.selectFixMassageByCon(page,user,fixPageVO);
    }

    @Override
    public Task getCreateUserByTaskId(Integer taskId) {
        return fixExecuteMapper.getCreateUserByTaskId(taskId);
    }

    @Override
    public List<FixAllMassage_lmg> selectFixAllMassageExl(FixPageVO_lmg fixPageVO) {
        return fixExecuteMapper.selectFixAllMassageExl(fixPageVO);
    }

    @Override
    public List<FixAllMassage_lmg> selectFixMassageByConExl(Users user, FixPageVO_lmg fixPageVO) {
        return fixExecuteMapper.selectFixMassageByConExl(user,fixPageVO);
    }



}
